﻿using MediatR;
using WMS.API.Application.Command.BasicManagement.ShelfManage;
using WMS.Domain.Entities.BasicManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.BasicManagement.ShelfManage
{
 
    public class DelShelfManageModelCommandHandler:IRequestHandler<DelShelfManageModelCommand,APIResult<int>>
    {
        /// <summary>
        /// 货架管理仓储
        /// </summary>
        IBaseRepository<ShelfManageModel> _shelfManageModelBaseRepository;

        public DelShelfManageModelCommandHandler(IBaseRepository<ShelfManageModel> shelfManageModelBaseRepository)
        {
            _shelfManageModelBaseRepository = shelfManageModelBaseRepository;
        }
        /// <summary>
        /// 删除货架命令行
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task<APIResult<int>> Handle(DelShelfManageModelCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var i =await _shelfManageModelBaseRepository.DeleteAsync(request.Id);
                return await Task.FromResult(i>0?new APIResult<int>("货架信息删除成功") { Code=ResultCode.Success}: new APIResult<int>("货架信息删除失败") { Code = ResultCode.Failed });
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
